package org.gensokyo

import org.json4s.CustomSerializer
import org.json4s.JsonAST.JString
import us.codecraft.webmagic.{Page, Request}

/**
  * Created by liusen on 16-12-1.
  */
package object crawler {

  implicit def addPageMethod(page: Page) = new {
    def addTargetRequests(requestList: List[Request]): Unit = requestList.foreach(page.addTargetRequest)
  }

  class EnumSerializer[E <: Enum[E]](implicit ct: Manifest[E]) extends CustomSerializer[E](format => ( {
    case JString(name) => Enum.valueOf(ct.runtimeClass.asInstanceOf[Class[E]], name)
  }, {
    case dt: E => JString(dt.name())
  }))


}
